#include "cpu/exec/template-start.h"

#define instr add

static void do_execute() {
	 DATA_TYPE result = op_dest->val + op_src->val;
    int len = (DATA_BYTE << 3) - 1;
    int s1, s2;
    
    s1 = op_dest->val >> len;
    s2 = op_src->val >> len;
    
    OPERAND_W(op_dest, result);
    update_eflags_pf_zf_sf((DATA_TYPE_S)result);
    if (DATA_BYTE == 1) cpu.eflags.CF = (uint8_t)result < (uint8_t)op_dest->val;
    else if (DATA_BYTE == 2) cpu.eflags.CF = (uint16_t)result < (uint16_t)op_dest->val;
    else if (DATA_BYTE == 4) cpu.eflags.CF = (uint32_t)result < (uint32_t)op_dest->val;
    
    cpu.eflags.SF = result >> len;
    cpu.eflags.OF = (s1 == s2 && s1 != cpu.eflags.SF);
    cpu.eflags.ZF = !result;
    
    DATA_TYPE pf_temp = result;
    pf_temp ^= pf_temp >> 4;
    pf_temp ^= pf_temp >> 2;
    pf_temp ^= pf_temp >> 1;
    cpu.eflags.PF = !(pf_temp & 1);
    
    print_asm_template2();
}

#if DATA_BYTE == 2 || DATA_BYTE == 4
make_instr_helper(si2rm)
#endif

make_instr_helper(i2a)
make_instr_helper(i2rm)
make_instr_helper(r2rm)
make_instr_helper(rm2r)

#include "cpu/exec/template-end.h"